package vip.lsjscl.flowboot.workflow.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import vip.lsjscl.flowboot.util.constants.ActivityStatus;
import vip.lsjscl.flowboot.workflow.entity.DKActivity;

/**
 * 活动存储库
 *
 * @author zhangxingju
 * @date 2025/02/14
 */
@Repository
public interface DKActivityRepository extends JpaRepository<DKActivity, String> {
    // 根据工作流版本ID查询所有活动
    List<DKActivity> findByWorkflowVersionIdAndBusinessId(String workflowVersionId, String businessId);

    // 根据活动名称查询所有活动
    @Query(value = "select * from dk_activity where name = :name and workflow_version_id = :workflowVersionId and business_id = :businessId", nativeQuery = true)
    List<DKActivity> findAllByNameAndWorkflowVersionIdAndBusinessId(@Param("name") String name, @Param("workflowVersionId") String workflowVersionId, @Param("businessId") String businessId);

    //根据业务ID查找活动节点
    List<DKActivity> findAllByBusinessId(String businessId);

    //根据业务ID查找活动节点,只查询第一个
    DKActivity findFirstByBusinessId(String businessId);

    /**
     * 获取最近一次退回申请人的节点
     *
     * @param businessId 业务id
     * @return {@link List }<{@link DKActivity }>
     */
    DKActivity findFirstByBusinessIdAndStatusOrderByUpdateTimeDesc(String businessId, ActivityStatus status);
}